function [ b ] = beta( s, g )

    b = zeros(2,s);
    
    for i = s:-1:1
        if(i == s)
            b(1,i) = 1;
            b(2,i) = 1;
        else
            b(1,i) = b(1,i+1)*M(1,1,i,g) + b(2,i+1)*M(1,2,i,g);
            b(2,i) = b(1,i+1)*M(2,1,i,g) + b(2,i+1)*M(2,2,i,g);
        end
    end
        
end

function [ m ] = M( y_, y, i, g )
    m = exp(g(y_,y,i));
end

